import axios from "axios";

export const getServiceUrlUrl = async (url) => {
  const u = new URL(url);
  try {
    const { data } = await axios({
      url: `${u.origin}/mop/service`,
      method: 'POST',
      params: {
        sign: u.searchParams.get('sign'),
      }
    });

    if(data.code === '200') {
      const [, serviceUrl] = data.data.split('----');
      return serviceUrl;
    }
    throw new Error(`${data.message}`);
  }catch (e) {
    console.error(e.message);
    throw new Error(`获取客服地址失败: ${e.message}`);
  }
}
